package com.goods.business.converter;

import com.goods.business.service.OutStockService;
import com.goods.common.response.ResponseBean;
import com.goods.common.utils.ListPageUtils;
import com.goods.common.vo.business.OutStockVO;
import com.goods.common.vo.system.PageVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(value = "物资发放")
@RestController
@RequestMapping("/business/outStock")
public class OutStockController {

    @Autowired
    private OutStockService outStockService;

    //http://www.localhost:8989/business/outStock/findOutStockList?pageNum=1&pageSize=10 status=0 outNum=31231 type=1
    //Request Method: GET
    @GetMapping("findOutStockList")
    public ResponseBean findOutStockList(Integer pageNum,Integer pageSize,Integer status,Integer type,String outNum){
        List<OutStockVO> outStockList =  outStockService.findOutStockList(status,type,outNum);
        List<OutStockVO> page = ListPageUtils.page(outStockList, pageSize, pageNum);
        PageVO<OutStockVO> outStockPageVO = new PageVO<>(outStockList.size(), page);
        return ResponseBean.success(outStockPageVO);
    }

    //添加去处
    // http://www.localhost:8989/business/outStock/addOutStock
    //Request Method: POST
    @PostMapping("/addOutStock")
    public ResponseBean addOutStock(@RequestBody OutStockVO outNum) {
        outStockService.addOutStock(outNum);

        return ResponseBean.success();
    }

    //删除http://www.localhost:8989/business/outStock/delete/18
    //Request Method: GET
    @GetMapping("/delete/{id}")
    public ResponseBean delete(@PathVariable Long id) {
        outStockService.delete(id);

        return ResponseBean.success();
    }
    //详细http://www.localhost:8989/business/outStock/detail/14?pageNum=1
    //Request Method: GET
    @GetMapping("/detail/{id}")
    public ResponseBean detail(@PathVariable Long id) {
        Map map = outStockService.detail(id);
        /** 返回值
         * this.detailTable = res.data.itemVOS
         * this.detailTotal = res.data.total
         * this.consumer = res.data.consumerVO
         * this.pStatus = res.data.status
         */
        return ResponseBean.success(map);
    }

    //通过 http://www.localhost:8989/business/outStock/publish/21
    //Request Method: PUT
    @PutMapping("/publish/{id}")
    public ResponseBean publish(@PathVariable Long id) {
        outStockService.publish(id);

        return ResponseBean.success();
    }



}
